<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-wShopPrice-add">
			<div class="form-group">
				<label class="col-sm-3 control-label">店铺：</label>
				<div class="col-sm-8">
					<select data-placeholder="选择店铺" name="shopId" id="shopId"
							class="form-control chosen-select" tabindex="2"
							style="width: 100%">
						<option value="">选择店铺</option>
						<option th:value="${shop.shopId}" th:each="shop:${shopList}" th:text="${shop.shopName}">选择服务</option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">服务类型：</label>
				<div class="col-sm-8">
					<select data-placeholder="选择服务类型" name="typeId" id="typeId"
							class="form-control chosen-select" tabindex="2"
							style="width: 100%"
							onchange="selectFunc()">
						<option value="">选择服务类别</option>
						<option th:value="${type.typeId}" th:each="type:${typeList}" th:text="${type.name}">选择服务</option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">服务名称：</label>
				<div class="col-sm-8">
					<select data-placeholder="选择服务" name="itemId" id="itemId"
							class="form-control chosen-select" tabindex="2"
							style="width: 100%" >
						<option value="">选择服务</option>
						<option th:value="${item.itemId}" th:each="item:${itemList}" th:text="${item.itemName}">选择服务</option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">服务价格：</label>
				<div class="col-sm-8">
					<input id="price" name="price" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<input id="remark" name="remark" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">状态：</label>
				<div class="col-sm-8">
					<div class="onoffswitch">
						<input type="checkbox" th:checked="true" class="onoffswitch-checkbox" id="status" name="status" />
						<label class="onoffswitch-label" for="status">
							<span class="onoffswitch-inner"></span>
							<span class="onoffswitch-switch"></span>
						</label>
					</div>
				</div>
			</div>
		</form>
	</div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		var prefix = ctx + "foxwash/wShopPrice"
		$("#form-wShopPrice-add").validate({
			rules:{
				xxxx:{
					required:true,
				},
			}
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	            //$.operate.save(prefix + "/add", $('#form-wShopPrice-add').serialize());
				add();
	        }
	    }

        function  add() {
            var shopId = $("#shopId option:selected").val();
            var typeId = $("#typeId option:selected").val();
            var itemId = $("#itemId option:selected").val();
            var price = $("input[name='price']").val();
            var remark = $("input[name='remark']").val();
            var status = $("input[name='status']").is(':checked') == true ? 0 : 1;
            $.ajax({
                cache : true,
                type : "POST",
                url : prefix + "/add",
                data : {
                    "shopId": shopId,
                    "typeId": typeId,
                    "itemId": itemId,
                    "price": price,
					"remark": remark,
                    "status": status
                },
                async : false,
                error : function(request) {
                    $.modal.alertError("系统错误");
                },
                success : function(data) {
                    $.operate.successCallback(data);
                }
            });
        }

        function selectFunc(){
		    //var vs = $('select option:selected').val();
            var typeId = $("#typeId option:selected").val();
            $.ajax({
                url : prefix+"/updateItem",
                type : "post",
                data : {
                    'typeId' : typeId
                },
                success : function(data) {
                    var data2 = eval(data.items);
                    if(data2 != null && data2.length > 0) {
                        var html="";
                        for (var i in data2) {
                            html+="<option value='"+data2[i].itemId+"'>"+data2[i].itemName+"</option>";
                        }
                    }
                    $("#itemId").html(html).selectpicker('refresh');
                }
            });
        }
	</script>
</body>
</html>
